﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public static class MD5Helper
    {


        //封装加密的方法：
        public static string GetMD5(string str)
        {
            using (MD5 md5 = MD5.Create())
            {
                //获取加密后的哈希码
                byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
                
                //将哈希码转化为十六进制
                StringBuilder sb = new StringBuilder();
                
                foreach(byte v in bytes)
                {
                    sb.Append(v.ToString("x2"));
                }

                return sb.ToString();
            }
        }
    }
}
